package org.fujay.langchain4jserver.application.service;

import org.fujay.langchain4jserver.application.command.CreateKnowledgeBaseCommand;
import org.fujay.langchain4jserver.application.command.UpdateKnowledgeBaseInfoCommand;
import org.fujay.langchain4jserver.application.dto.FileDTO;
import org.fujay.langchain4jserver.application.dto.KnowledgeBaseDTO;
import org.fujay.langchain4jserver.application.dto.KnowledgeBaseIndexStatusDTO;
import org.fujay.langchain4jserver.application.dto.KnowledgeBaseSummaryDTO;
import org.fujay.langchain4jserver.domain.knowledge.vo.FileId;
import org.fujay.langchain4jserver.domain.knowledge.vo.KnowledgeBaseId;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Optional;

/**
 * 知识库应用服务接口
 */
public interface KnowledgeBaseService {

    /**
     * @author sunliming
     * @description 新建知识库
     */
    KnowledgeBaseDTO createKnowledgeBase(CreateKnowledgeBaseCommand command);

    Optional<KnowledgeBaseDTO> getKnowledgeBase(KnowledgeBaseId id);

    List<KnowledgeBaseSummaryDTO> listKnowledgeBases();

    void updateKnowledgeBaseInfo(UpdateKnowledgeBaseInfoCommand command);

    void deleteKnowledgeBase(KnowledgeBaseId id);

    // --- 文件管理 ---

    /**
     * 上传文件并将其添加到知识库
     *
     * @param knowledgeBaseId 知识库ID
     * @param file            上传的文件
     * @return 添加的文件 DTO
     */
    FileDTO uploadAndAddFile(KnowledgeBaseId knowledgeBaseId, MultipartFile file);

    List<FileDTO> listFiles(KnowledgeBaseId knowledgeBaseId);

    void deleteFile(KnowledgeBaseId knowledgeBaseId, FileId fileId);

    // --- 索引触发 (异步) ---
    void triggerIndexFileAsync(KnowledgeBaseId knowledgeBaseId, FileId fileId);

    void triggerIndexKnowledgeBaseAsync(KnowledgeBaseId knowledgeBaseId);

    void triggerRebuildIndexAsync(KnowledgeBaseId knowledgeBaseId);

    /**
     * 获取知识库索引状态 (返回 DTO)
     *
     * @param knowledgeBaseId 知识库 ID
     * @return 知识库索引状态 DTO
     */
    KnowledgeBaseIndexStatusDTO getKnowledgeBaseStatus(KnowledgeBaseId knowledgeBaseId);
}
